1
|
|
|
/* |
2
|
|
|
* CMS Pico - Integration of Pico within your files to create websites. |
3
|
|
|
* |
4
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
5
|
|
|
* later. See the COPYING file. |
6
|
|
|
* |
7
|
|
|
* @author Maxence Lange <[email protected]> |
8
|
|
|
* @copyright 2017 |
9
|
|
|
* @license GNU AGPL version 3 or any later version |
10
|
|
|
* |
11
|
|
|
* This program is free software: you can redistribute it and/or modify |
12
|
|
|
* it under the terms of the GNU Affero General Public License as |
13
|
|
|
* published by the Free Software Foundation, either version 3 of the |
14
|
|
|
* License, or (at your option) any later version. |
15
|
|
|
* |
16
|
|
|
* This program is distributed in the hope that it will be useful, |
17
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
18
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19
|
|
|
* GNU Affero General Public License for more details. |
20
|
|
|
* |
21
|
|
|
* You should have received a copy of the GNU Affero General Public License |
22
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
23
|
|
|
* |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
/** global: OC */ |
27
|
|
|
/** global: pico_elements */ |
28
|
|
|
/** global: pico_result */ |
29
|
|
|
/** global: pico_define */ |
30
|
|
|
|
31
|
|
|
var pico_nav = { |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
retrieveWebsites: function () { |
35
|
|
|
$.ajax({ |
36
|
|
|
method: 'GET', |
37
|
|
|
url: OC.generateUrl('/apps/cms_pico/personal/websites'), |
38
|
|
|
data: {} |
39
|
|
|
}).done(function (res) { |
40
|
|
|
pico_nav.retrieveWebsitesResult(res); |
41
|
|
|
}); |
42
|
|
|
}, |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
retrieveWebsitesResult: function (result) { |
46
|
|
|
if (result.status === 1) { |
47
|
|
|
pico_define.themes = result.themes; |
48
|
|
|
pico_result.displayWebsites(result.websites); |
49
|
|
|
return; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
OCA.notification.onFail( |
|
|
|
|
53
|
|
|
t('cms_pico', "It was not possible to retrieve the complete list of your websites") + |
54
|
|
|
': ' + ((result.error) ? result.error : t('cms_pico', 'no error message'))); |
55
|
|
|
}, |
56
|
|
|
|
57
|
|
|
|
58
|
|
|
updateNewWebsite: function (url) { |
59
|
|
|
pico_elements.cms_pico_new_url.text(pico_define.nchost + pico_define.sites + url); |
60
|
|
|
pico_nav.refreshNewFolder(); |
61
|
|
|
}, |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
updateTheme: function (site_id, theme) { |
65
|
|
|
$.ajax({ |
66
|
|
|
method: 'PUT', |
67
|
|
|
url: OC.generateUrl('/apps/cms_pico/personal/website/' + site_id + '/theme'), |
68
|
|
|
data: { |
69
|
|
|
theme: theme |
70
|
|
|
} |
71
|
|
|
}).done(function (res) { |
72
|
|
|
pico_nav.updateThemeResult(res); |
73
|
|
|
}); |
74
|
|
|
}, |
75
|
|
|
|
76
|
|
|
|
77
|
|
|
updateThemeResult: function (result) { |
78
|
|
|
if (result.status === 1) { |
79
|
|
|
OCA.notification.onSuccess('Theme updated'); |
|
|
|
|
80
|
|
|
pico_result.displayWebsites(result.websites); |
81
|
|
|
return; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
OCA.notification.onFail( |
85
|
|
|
t('cms_pico', "It was not possible to update your theme on {name}", |
86
|
|
|
{name: result.name}) + |
87
|
|
|
': ' + ((result.error) ? result.error : t('cms_pico', 'no error message'))); |
88
|
|
|
}, |
89
|
|
|
|
90
|
|
|
|
91
|
|
|
pickFolderResult: function (folder) { |
92
|
|
|
pico_elements.cms_pico_new_folder_result = folder; |
93
|
|
|
pico_nav.refreshNewFolder(); |
94
|
|
|
}, |
95
|
|
|
|
96
|
|
|
|
97
|
|
|
refreshNewFolder: function () { |
98
|
|
|
pico_elements.cms_pico_new_folder.val(pico_elements.cms_pico_new_folder_result + '/' + |
99
|
|
|
pico_elements.cms_pico_new_website.val()); |
100
|
|
|
}, |
101
|
|
|
|
102
|
|
|
|
103
|
|
|
createNewWebsite: function () { |
104
|
|
|
|
105
|
|
|
pico_nav.creatingWebsite(true); |
106
|
|
|
var data = { |
107
|
|
|
name: pico_elements.cms_pico_new_name.val(), |
108
|
|
|
website: pico_elements.cms_pico_new_website.val(), |
109
|
|
|
path: pico_elements.cms_pico_new_folder.val(), |
110
|
|
|
template: pico_elements.cms_pico_new_template.val() |
111
|
|
|
}; |
112
|
|
|
|
113
|
|
|
$.ajax({ |
114
|
|
|
method: 'PUT', |
115
|
|
|
url: OC.generateUrl('/apps/cms_pico/personal/website'), |
116
|
|
|
data: { |
117
|
|
|
data: data |
118
|
|
|
} |
119
|
|
|
}).done(function (result) { |
120
|
|
|
pico_nav.creatingWebsite(false); |
121
|
|
|
pico_result.createNewWebsiteResult(result); |
122
|
|
|
}); |
123
|
|
|
|
124
|
|
|
}, |
125
|
|
|
|
126
|
|
|
|
127
|
|
|
deleteWebsite: function (id, name) { |
128
|
|
|
|
129
|
|
|
OC.dialogs.confirm( |
130
|
|
|
t('cms_pico', |
131
|
|
|
"This operation will delete the website {name} but its content will still be available in your files", |
132
|
|
|
{name: name}), |
133
|
|
|
t('cms_pico', 'Please confirm'), |
134
|
|
|
function (e) { |
135
|
|
|
if (e === true) { |
136
|
|
|
pico_nav.forceDeleteWebsite(id, name); |
137
|
|
|
} |
138
|
|
|
}); |
139
|
|
|
}, |
140
|
|
|
|
141
|
|
|
|
142
|
|
|
forceDeleteWebsite: function (id, name) { |
143
|
|
|
$.ajax({ |
144
|
|
|
method: 'DELETE', |
145
|
|
|
url: OC.generateUrl('/apps/cms_pico/personal/website'), |
146
|
|
|
data: { |
147
|
|
|
data: { |
148
|
|
|
id: id, |
149
|
|
|
name: name |
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
}).done(function (result) { |
153
|
|
|
pico_result.deleteWebsiteResult(result); |
154
|
|
|
}); |
155
|
|
|
}, |
156
|
|
|
|
157
|
|
|
|
158
|
|
|
creatingWebsite: function (creating) { |
159
|
|
|
|
160
|
|
|
pico_elements.cms_pico_new_submit.prop('disabled', creating); |
161
|
|
|
if (creating) { |
162
|
|
|
pico_elements.cms_pico_new_submit.val(t('cms_pico', 'Please wait')); |
163
|
|
|
} else { |
164
|
|
|
pico_elements.cms_pico_new_submit.val(t('cms_pico', 'Create a new website')); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
}, |
168
|
|
|
|
169
|
|
|
|
170
|
|
|
updateWebsiteOption: function (site_id, key, value) { |
171
|
|
|
$.ajax({ |
172
|
|
|
method: 'POST', |
173
|
|
|
url: OC.generateUrl('/apps/cms_pico/personal/website/' + site_id + '/option/' + key), |
174
|
|
|
data: { |
175
|
|
|
value: value |
176
|
|
|
} |
177
|
|
|
}).done(function (res) { |
178
|
|
|
pico_nav.updateWebsiteOptionResult(res); |
179
|
|
|
}); |
180
|
|
|
}, |
181
|
|
|
|
182
|
|
|
|
183
|
|
|
updateWebsiteOptionResult: function (result) { |
184
|
|
|
if (result.status === 1) { |
185
|
|
|
OCA.notification.onSuccess('Option updated'); |
|
|
|
|
186
|
|
|
pico_result.displayWebsites(result.websites); |
187
|
|
|
return; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
OCA.notification.onFail( |
191
|
|
|
t('cms_pico', "It was not possible to update your website") + |
192
|
|
|
': ' + ((result.error) ? result.error : t('cms_pico', 'no error message'))); |
193
|
|
|
}, |
194
|
|
|
|
195
|
|
|
|
196
|
|
|
resetFields: function () { |
197
|
|
|
pico_elements.cms_pico_new_website.val(''); |
198
|
|
|
pico_elements.cms_pico_new_name.val(''); |
199
|
|
|
pico_elements.cms_pico_new_folder.val('/'); |
200
|
|
|
pico_elements.cms_pico_new_url.text(''); |
201
|
|
|
}, |
202
|
|
|
|
203
|
|
|
|
204
|
|
|
generateTmplWebsite: function (entry) { |
205
|
|
|
var div = $('#tmpl_website'); |
206
|
|
|
if (!div.length) { |
207
|
|
|
return; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
var tmpl = div.html(); |
211
|
|
|
|
212
|
|
|
tmpl = tmpl.replace(/%%id%%/g, entry.id); |
213
|
|
|
tmpl = tmpl.replace(/%%name%%/g, escapeHTML(entry.name)); |
214
|
|
|
tmpl = tmpl.replace(/%%address%%/g, pico_define.nchost + pico_define.sites + |
215
|
|
|
escapeHTML(entry.site)); |
216
|
|
|
tmpl = tmpl.replace(/%%path%%/g, escapeHTML(entry.path)); |
217
|
|
|
tmpl = tmpl.replace(/%%theme%%/g, escapeHTML(entry.theme)); |
218
|
|
|
|
219
|
|
|
if (entry.options.private === '1') { |
220
|
|
|
tmpl = tmpl.replace(/%%private%%/g, escapeHTML(entry.options.private)); |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
return tmpl; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
|
227
|
|
|
}; |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.